using System;
using System.Collections;
using DG.Tweening;
using UnityEngine;

public class DisplayAnimation : MonoBehaviour
{
    [SerializeField]
    private Transform m_NaxidaMask;
    
    void OnEnable()
    {
        Application.targetFrameRate = 240;
        
        DOTween.KillAll();
        
        this.m_NaxidaMask.localScale = new Vector3(5.8f, 10f, 1f) * 10f;
        this.m_NaxidaMask.DOScale(new Vector3(5.8f, 10f, 1f), 3f).SetEase(Ease.InOutQuint).OnComplete(() =>
        {
            transform.DORotate(new Vector3(0f, 180f, 0f), 3f, RotateMode.FastBeyond360).SetEase(Ease.InOutQuint).OnComplete(() =>
            {
                transform.Find("ModeRoot/NahidaUnityModel").GetComponent<Animator>().applyRootMotion = true;
                transform.DORotate(new Vector3(0f, 360f, 0f), 3f, RotateMode.FastBeyond360).SetEase(Ease.InOutQuint).OnComplete(() =>
                {
                    StartCoroutine(MyCoroutine());
                });
            });
        });
    }
    
    [SerializeField]
    private float m_IdleRotateSpeed = 360f;
    
    [SerializeField]
    private float m_IdleRotateRange = 10f;
    IEnumerator MyCoroutine()
    {
        var tmpTime = 0f;
        var rotateRange = 0f;
        var rotateSpeed = 0f;
        
        while (Application.isPlaying)
        {
            rotateRange = Mathf.Min(rotateRange + Time.deltaTime, this.m_IdleRotateRange); 
            rotateSpeed = Mathf.Min(rotateSpeed + Time.deltaTime * 2f, this.m_IdleRotateSpeed);
            
            tmpTime += Time.deltaTime * rotateSpeed;
            var eulerAngles = transform.localEulerAngles;
            eulerAngles.y = Mathf.Sin(tmpTime) * rotateRange;
            eulerAngles.x = Mathf.Cos(tmpTime) * rotateRange;
            transform.localEulerAngles = eulerAngles;
            
            yield return new WaitForEndOfFrame();
        }
        Debug.Log("开始");
        yield return new WaitForSeconds(2f); // 等待2秒
        Debug.Log("2秒后执行");
    }
}
